var util = require('../../utils/util.js');
var api = require('../../config/api.js');

Page({
  data: {
    addressInfo:{},
    orderId: 0,
    markers: [],
    circles: [],
    textArr:[
      '',
      '10分钟内未支付将自动取消',
      '订单正在打包中，完成后将第一时间为您配送',
      '订单已经到团长那里了，快去提货吧',
      '感谢您选择獭獭同城，期待下次为您继续服务～',
      '感谢您选择獭獭同城，期待下次为您继续服务～',
      '订单已完成退款，欢迎再次选择獭獭',
      '客服整理您的订单，请稍等',
      '订单已完成退款，欢迎再次选择獭獭',
      '您的订单不符合退款条件，请见谅'
    ],
    orderInfo: {},
    orderGoods: [],
    handleOption: {},
      expressInfo:{},
      expressTraces:[]
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    this.setData({
      orderId: options.id
    });
    this.getOrderDetail();
  },
    onPullDownRefresh: function () {
        this.getOrderDetail();
    },
  getOrderDetail() {
    let that = this;
    util.request(api.orderUrl.orderDetail, {
      orderId: that.data.orderId
    }).then(function (res) {
      console.log(2223,res)
      if (res.code == 200) {
        that.setData({
          orderInfo: res.result,
          orderGoods: res.result.orderCommodityList,
        });
      }
    });
  },
  makePhone() {
    let phone = this.data.orderInfo.leaderPhone;
    wx.makePhoneCall({
      phoneNumber: phone,
      success: function(res) {
        console.log(res)
      }
    })
  },
  payTimer() {
    let that = this;
    let orderInfo = that.data.orderInfo;

    setInterval(() => {
      console.log(orderInfo);
      orderInfo.add_time -= 1;
      that.setData({
        orderInfo: orderInfo,
      });
    }, 1000);
  },
  payOrder() {
    let that = this;
    util.request(api.PayPrepayId, {
      orderId: that.data.orderId
    }).then(function (res) {
      if (res.errno === 0) {
        const payParam = res.data;
        wx.requestPayment({
          'timeStamp': payParam.timeStamp,
          'nonceStr': payParam.nonceStr,
          'package': payParam.package,
          'signType': payParam.signType,
          'paySign': payParam.paySign,
          'success': function (res) {
            console.log(res)
          },
          'fail': function (res) {
            console.log(res)
          }
        });
      }
    });

  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  }
})